package com.gofbox.api.user;

import com.alibaba.dubbo.config.annotation.Service;
import com.box.user.mapper.BaseUserMapper;
import com.box.user.model.BaseUser;
import com.box.user.model.BaseUserExample;
import com.gofbox.plugin.mybatis.Limit;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by aoc on 2016/10/18.
 */
@Service(version = "1.0.0")
public class BaseUserRemote implements IBaseUserRemote {
    @Autowired
    private BaseUserMapper baseUserMapper;

    @Override
    public List<BaseUser> getUserByAll(List<Long> userIds) {
        BaseUserExample example=new BaseUserExample();
        if (userIds!=null&&userIds.size()>0)
        {
            example.createCriteria().andIdIn(userIds);
        }
        return  baseUserMapper.selectByExample(example);
    }

    @Override
    public boolean addUser(BaseUser baseUser) {
        return baseUserMapper.insertSelective(baseUser)>0?true:false;
    }

    @Override
    public boolean updateUser(BaseUser baseUser) {
        return baseUserMapper.updateByPrimaryKeySelective(baseUser)>0?true:false;
    }

    @Override
    public boolean delUser(BaseUser baseUser) {
     return   baseUserMapper.updateByPrimaryKey(baseUser)>0?true:false;
    }
    @Override
    public List<BaseUser> getUser(List<Long> userIds,int start,int end) {
        BaseUserExample example=new BaseUserExample();
        if (userIds!=null&&userIds.size()>0)
        {
            example.createCriteria().andIdIn(userIds);
        }
        example.setLimit(new Limit(start,end));
        example.setOrderByClause("create_time desc ");
        return  baseUserMapper.selectByExample(example);
    }
}
